<?
ini_set("display_errors",1);
include($_SERVER['DOCUMENT_ROOT'].'/includes/functions.inc.php');
include($_SERVER['DOCUMENT_ROOT'].'/portals/config.php');
include($_SERVER['DOCUMENT_ROOT'].'/groups/database.php');

init_session();



include($_SERVER['DOCUMENT_ROOT'].'/portals/header.inc.php');



?>

<h3>Welcome to the Experimental Geograph Portal Section</h3>

<p>Below is a selection of portals... (Click a red pin to visit the Portal)</p>

<?

$sql = array();
$sql['columns'] = 'p.*,images,GREATEST(0.3,avgdiam) AS avgdiam,wgs84_lat,wgs84_long';
$sql['tables'] = array();
$sql['tables'][] = "portal p";
$sql['tables'][] = "inner join cluster c using (portal_id)";
$sql['tables'][] = "inner join geograph_live.gridimage_search gs using (gridimage_id)";
$sql['wheres'] = array();

$sql['wheres'][] = "p.status_id = 1";
$sql['wheres'][] = "public = 'Y'";
$sql['wheres'][] = "level = 1";
$sql['wheres'][] = "avgdiam <= 200";
$sql['wheres'][] = "images > 10";



$sql['order'] = "avgdiam ASC";

$sql['limit'] = 25;

$query = sqlMakeQuery($sql);

$query = "SELECT * FROM ($query) t1 ORDER BY avgdiam DESC";

$data = getAssoc($query);



if ($data) {
	
?>

<style type="text/css"> 
#map {
	width: 700px;
	height: 800px;
}
</style> 

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 

<script type="text/javascript"> 
	// ripped from:
	// http://gmaps-samples-v3.googlecode.com/svn/trunk/circle-overlay/circle-overlay.html
	// and
	// http://stackoverflow.com/questions/1751710/google-maps-v3-api-mouseover-with-polygons
	
	var map = null;
	
	function createMarker(position,title,radius,url) {
		// Create a draggable marker which will later on be binded to a
		// Circle overlay.
		var marker = new google.maps.Marker({
			map: map,
			position: position,
			title: title
		});

		// Add a Circle overlay to the map.
		var circle = new google.maps.Circle({
			map: map,
			radius: radius 
		});

		// Since Circle and Marker both extend MVCObject, you can bind them
		// together using MVCObject's bindTo() method.  Here, we're binding
		// the Circle's center to the Marker's position.
		// http://code.google.com/apis/maps/documentation/v3/reference.html#MVCObject
		circle.bindTo('center', marker, 'position');
		
		var defaultColour = circle.get('fillColor');
		
		google.maps.event.addListener(marker,"mouseover",function(){ circle.setOptions({fillColor: "#00FF00"}); });
		
		google.maps.event.addListener(marker,"mouseout",function(){ circle.setOptions({fillColor: defaultColour}); });
		
		google.maps.event.addListener(marker, 'click', function() {
			location.href = url;
		});
		
	}

	function init() {
		var mapCenter = new google.maps.LatLng(54.55,-3.88);
		map = new google.maps.Map(document.getElementById('map'), {
			'zoom': 6,
			'center': mapCenter,
			'mapTypeId': google.maps.MapTypeId.TERRAIN
		});
		
		
		<?
		
		foreach ($data as $id => $c) {
			print "createMarker(new google.maps.LatLng({$c['wgs84_lat']},{$c['wgs84_long']}),'{$c['title']} [{$c['images']} images]',{$c['avgdiam']}*1000,'http://".he($c['domain']).".portal.geographs.org/');\n";
		}
		
		?>
		
	}

	// Register an event listener to fire when the page finishes loading.
	google.maps.event.addDomListener(window, 'load', init);
</script> 


	<div id="map"></div> 
<?

} else {
	print "<p>No Portals to show at this time. <a href=\"edit.php\">Create one</a>!</p>";
}


include($_SERVER['DOCUMENT_ROOT'].'/portals/footer.inc.php');
